package com.dragon.backstage.controller;

import com.dragon.backstage.domain.param.userLoginLog.UserLoginLogParam;
import com.dragon.backstage.domain.vo.userLoginLog.UserLoginLogVo;
import com.dragon.backstage.service.UserLoginLogService;
import com.dragon.common.annotation.AuthPermission;
import com.dragon.common.annotation.UserOperatorLog;
import com.dragon.common.domain.vo.PaginationVo;
import com.dragon.common.enums.BusinessType;
import com.dragon.common.utils.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 用户登陆记录 前端控制器
 * </p>
 *
 * @author dragon
 * @since 2024-08-01 18:08:24
 */
@RestController
@RequestMapping("/api/system/userLoginLog")
@Tag(name = "用户登陆日志模块接口")
public class UserLoginLogController {

    @Resource
    private UserLoginLogService userLoginLogService;


    /**
     * 用户登陆日志列表
     */
    @GetMapping("/list")
    @Operation(summary = "用户登陆日志列表")
    @AuthPermission(value = "system.user.login.log.list")
    public AjaxResult<PaginationVo<UserLoginLogVo>> list(UserLoginLogParam userLoginLogParam) {
        return userLoginLogService.userLoginLogList(userLoginLogParam);
    }

    /**
     * 删除用户登陆日志
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除用户登陆日志")
    @AuthPermission(value = "system.user.login.log.delete")
    @UserOperatorLog(title = "用户登陆日志", businessType = BusinessType.DELETE)
    public AjaxResult<Void> delete(@RequestParam(value = "loginIds", required = false) List<Long> loginIds) {
        return userLoginLogService.deleteUserLoginLog(loginIds);
    }

    /**
     * 导出用户登陆日志
     */
    @GetMapping("/export")
    @Operation(summary = "导出用户登陆日志")
    @AuthPermission(value = "system.user.login.log.export")
    @UserOperatorLog(title = "用户登陆日志", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, UserLoginLogParam userLoginLogParam) throws IOException {
        userLoginLogService.exportUserLoginLog(response, userLoginLogParam);
    }

    /**
     * 清空用户登陆日志
     */
    @DeleteMapping("/clean")
    @Operation(summary = "清空用户登陆日志")
    @AuthPermission(value = "system.user.login.log.clean")
    @UserOperatorLog(title = "用户登陆日志", businessType = BusinessType.CLEAN)
    public AjaxResult<Void> clean() {
        return userLoginLogService.cleanUserLoginLog();
    }

}
